#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

int t,n;
int nums[200005];

long long a()
{
    string s = "";
    long long ans = 0;
    for(long long i = 0;i <= (1ull<<n);i++)
    {
        s = "";
        for(int j = 0;j < n;j++)
        {
            int m = i;
            if((m>>j)%2)
            {
                s = "r"+s;
            }
            else
            {
                s = "b"+s;
            }
        }
        //cout<<s<<endl;
        long long l = 0;
        for(int j = n-1;j >= 0;j--)
        {
            for(int k = j-1;k >= 0;k--)
            {
                if(s[k]==s[j])
                {
                    if(nums[k+1]==nums[j+1])
                    {
                        l += nums[k+1];
                    }
                    break;
                }
            }
        }
        ans = max(ans,l);
    }
    return ans;
}

int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(int i = 1;i <= t;i++)
    {
        cin>>n;
        for(int j= 1;j <= n;j++)
        {
            cin>>nums[j];
        }
        cout<<a()<<endl;
    }
    return 0;
}
